package com.ymatou.app.rec.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.rec.parameter.SearchProductInAppBean;
import com.ymatou.app.rec.service.SearchProductInAppCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.database.sqlwapper.AppDefaultWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
/**
*查找好货商品接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SearchProductInApp{
	private static SearchProductInAppBean searchproductinappBean;
	private static SearchProductInAppCall searchproductinappCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查找好货商品接口");
	}

	@Before
	public void caseUp() {
		searchproductinappBean=new SearchProductInAppBean();
		searchproductinappCall=new SearchProductInAppCall();
		String text= "测试";
		String textUsql = "keyword(mixkeyword,"+text+")";
		searchproductinappBean.setModule("product_list");
		searchproductinappBean.setAppkey(3);
		searchproductinappBean.setQuery(textUsql);
	}

	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(searchproductinappCall.getOpurl());
		//Logger.generateResult();
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SearchProductInApp_001() {
		Logger.start(true,"app中查找好货商品接口调用成功");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			searchproductinappBean.setModule("product_list");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,测试)");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();			
			Logger.comment("searchproductinappCall send:" + searchproductinappCall.getEntityString());
			Logger.comment("searchproductinappCall response:" + searchproductinappCall.getReturnData());
			
			Logger.verifyEquals("OK",searchproductinappCall.getSuccess(), "接口调用是否成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_SearchProductInApp_002() {
		Logger.start(true,"app中查找好货商品接口返回记录数是否正确");
		
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			String text= "测试";
			
			searchproductinappCall.setData(searchproductinappBean);
			List<Map> list=new DefaultWapper().selectProductInPc(text);
			List<Map> list2 = new AppDefaultWapper().selectProductInApp(text);
			int returnNum =(Integer) list.get(0).get("num")+ (Integer) list2.get(0).get("num");
			searchproductinappCall.setData(searchproductinappBean);
			   
			searchproductinappCall.callService();	
		//	Logger.debug("*"+ searchproductinappCall.getTotal()+"*"+list);
			Logger.comment("searchproductinappCall send:" + searchproductinappCall.getEntityString());
			Logger.comment("searchproductinappCall response:" + searchproductinappCall.getReturnData());
		   
		    
			Logger.verifyEquals(returnNum, searchproductinappCall.getTotal(),"app中查找好货商品接口返回记录数是否正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SearchProductInApp_003() {
		Logger.start(true,"app中查找好货商品接口超时");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			searchproductinappBean.setModule("product_list");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,测试)");
			
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();		
			
			Logger.comment("searchproductinappCall send:" + searchproductinappCall.getEntityString());
			Logger.comment("searchproductinappCall response:" + searchproductinappCall.getReturnData());
			Logger.verifyEquals(false,searchproductinappCall.getTimeOut(), "app中查找好货商品接口是否超时");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}